package com.webchat.client.mall.config;

import com.webchat.client.mall.config.interceptor.SafeClickInterceptor;
import com.webchat.common.config.interceptor.ValidateLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MallWebMvcConfig implements WebMvcConfigurer {

    private static final String CLINT_REQUEST_PATH_PREFIX = "/mall-service/**";

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(validateLoginInterceptor()).addPathPatterns(CLINT_REQUEST_PATH_PREFIX).order(-5);

        /**
         * 注册安全点击拦截器
         */
        registry.addInterceptor(safeClickInterceptor()).addPathPatterns(CLINT_REQUEST_PATH_PREFIX).order(-2);
    }

    @Bean
    public SafeClickInterceptor safeClickInterceptor() {
        return new SafeClickInterceptor();
    }

    @Bean
    public ValidateLoginInterceptor validateLoginInterceptor() {
        return new ValidateLoginInterceptor();
    }
}
